-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More precise newsflash coordinates (using Waze data) #1552
base: dev
Are you sure you want to change the base?
More precise newsflash coordinates (using Waze data) #1552
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #1552 +/- ##
==========================================
+ Coverage 50.38% 51.35% +0.97%
==========================================
Files 62 62
Lines 5724 6048 +324
==========================================
+ Hits 2884 3106 +222
- Misses 2840 2942 +102
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! I have added some comments, but they are mostly minor suggestions.
I am not entirely sure the best way of adding SQL rows for tests is using this "add, commit; use; delete, commit" pattern; I'm not an expert, but I think it could be done using something like "add; use; rollback" pattern. Maybe @ziv17 would like to comment on this.
You can mock the db to return what you need for the test. Using mock you get much faster tests, and it is easier to test for boundary conditions. The tests can run the tests directly from the IDE. |
…hub.com/sahare92/anyway into better-precision-news-flash-coordinates
@ziv17 I think there's a benefit to run the query on the db (instead of mocking), because this way we can test that the generated query is working, and actually returns the expected WazeAlert from the db. |
I agree with Ziv. Mocking is generally better, and it's how other tests are written. If you want to test querying the DB, that would be a different test. |
tests/test_news_flash.py
Outdated
_delete_waze_alert(waze_alert.id) | ||
|
||
|
||
def _create_waze_accident_alert(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that you're using the context manager, there's no need to write these two functions separately. Just inline them.
.filter(WazeAlert.alert_type == "ACCIDENT") | ||
.filter( | ||
WazeAlert.created_at.between( | ||
newsflash.date - timedelta(hours=WAZE_ALERT_NEWSFLASH_DELTA_IN_HOURS), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this constant is only used inside the function, it's should probably be local constant. This way the occasional reader doesn't have to wonder where else it is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, it can be a timedelta
, making it slightly more type-safe, and making this expression a single line.
We do need both end-to-end tests and tests to cover the logic. Covering the logic with end-to-end will be slow, unstable, and cumbersome. The best practice is small amount of end-to-end and and reach coverage with unit tests (that use mocking) |
Hi @sahare92 , great work! |
@Mano3 thanks,
|
Added a simple logic to find the related waze accident alert using information from the newsflash
(Currently it selects a waze accident that occurred around the area of the newsflash accident , up to
WAZE_ALERT_NEWSFLASH_DELTA_IN_HOURS
hours before the newsflash's time.It currently only populates the
newsflash.waze_alert
property, without modifying the lat/lon attributes according to the waze accident (this should be updated after we test it manually, and make sure it indeed improves the precision)